package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.repository.StrategyResp;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import com.fywsy.fyweb.utils.TextUtils;
import com.google.gson.Gson;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(75)
public class LiangTian13GameStrategy extends BaseGameStrategy {

    public static final String URL = "http://114.66.45.45:8081/gmss/user/gmquery.php";

    public static final String DELITEM = "http://114.66.45.45:8081/gmss/user/delItem.php";

    /**
     *
     * type=mail&checknum=diyao88&uid=m66666&item=25&num=123&qu=1
     * @param item
     * @return
     */

    @GongnengMethod(7501)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("type", "mail");
        params.add("checknum", "diyao88");
        params.add("qu", "1");
        params.add("uid", item.uid);
        params.add("item", item.itemId);
        params.add("num", item.number);
        return RestTemplateUtil.sendPostFormAndGetJsonKey(URL,params,"info");
    }


    @GongnengMethod(7502)
    public String del(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("qu", "1");
        params.add("uid", item.uid);
        params.add("itemId", item.itemId);
        params.add("number", item.number);
        String result = RestTemplateUtil.sendPostForm(DELITEM,params);
        return !TextUtils.isEmpty(result) && result.contains("成功") ? "操作成功" : result;
    }

    @GongnengMethod(602)
    public String day(SendItem item) {
        return mail(item);
    }

    @GongnengMethod(2)
    public String pay(SendItem item) {
        System.out.println("发送充值：金额：");
        return "充值已发送，金额：";
    }

    @GongnengMethod(4)
    public String cleat(SendItem item) {
        System.out.println("清除成功");
        return "清除成功";
    }


    public static void main(String[] args) {
        LiangTian13GameStrategy strategy = new LiangTian13GameStrategy();

        // 测试发送物品
        SendItem item = new SendItem();
        item.uid = "m66666";
        item.itemId = "7009";
        item.number = "6000";
        System.out.println("发送物品结果：" + strategy.del(item));
    }
}

